home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / ka9q / kit_src / mk_dir.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-03  |  1.4 KB  |  61 lines

  1. /*    (C) Copyright 1991 Dave Fritsche (wb8zxu), All Rights Reserved.
  2.  * 
  3.  *    Redistribution and use in source and binary forms are permitted for
  4.  *    non-commercial use, provided that the above copyright notice and this
  5.  *    paragraph are duplicated in all such forms.  THIS SOFTWARE IS PROVIDED
  6.  *    ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
  7.  *    WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND
  8.  *    FITNESS FOR A PARTICULAR PURPOSE.
  9.  */
  10. #include <stdio.h>
  11. #include <sys\stat.h>
  12. #include <string.h>
  13. #include "screen.h"
  14.  
  15. mk_dir(dirpath)
  16. unsigned char dirpath[];
  17. {
  18.     int rtn, m, n;
  19.     unsigned char pathtmp[128], tmp[128], *ch;
  20.     struct stat statbuf;
  21.  
  22.     strcpy(pathtmp, dirpath);
  23.     ch = strtok(pathtmp, "\\");
  24.     strcpy(tmp, ch);
  25.  
  26.     while (1)
  27.     {
  28.         if ( (ch = strtok(NULL, "\\")) == NULL )
  29.         {
  30.             if (debug)
  31.                 printf("***> mkdir %s -- already exists\n", tmp);
  32.             return(0);
  33.         }
  34.         strcat(tmp, "\\");
  35.         strcat(tmp, ch);
  36.         if (stat(tmp, &statbuf) != 0)
  37.             break;
  38.         if ( (statbuf.st_mode & S_IFDIR) == 0 )
  39.         {
  40.             printf("\n(%s) is not a directory, can't proceed\n\n",
  41.                     tmp);
  42.             exit(1);
  43.         }
  44.     }
  45.  
  46.     if (debug)
  47.         printf("***> mkdir %s\n", tmp);
  48.     else
  49.         mkdir(tmp);
  50.  
  51.     while ( (ch = strtok(NULL, "\\")) != NULL )
  52.     {
  53.         strcat(tmp, "\\");
  54.         strcat(tmp, ch);
  55.         if (debug)
  56.             printf("***> mkdir %s\n", tmp);
  57.         else
  58.             mkdir(tmp);
  59.     }
  60. }
  61.